t= input ()
 
if len(str(t))!= 4:
    print(0)
else:
    g = False
    for length in range(4, 0, -1):
        if g:
            break
        for i in range(4 - length + 1):
            n = int(str(t)[i:i+length])
            if n < 2:
                continue
            for j in range(2, int(n**0.5) + 1):
                if n % j == 0:
                    break
            else:
                print(n)
                g = True
                break
    if not g:
        print(0)
